/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) {
    int n = nums1Size > nums2Size ? nums1Size : nums2Size;
    int* ans = (int*)malloc(sizeof(int)*(n));
    int hash[1001] = { 0 };
    *returnSize = 0;
    int i = 0;
    for (i = 0; i < nums1Size; i++)
    {
        hash[nums1[i]]  = 1;
    }
    for (i = 0; i < nums2Size; i++)
    {
        if (hash[nums2[i]])
        {
            ans[(*returnSize)++] = nums2[i];
            --hash[nums2[i]];
        }
    }
    return ans;
}